var bird;

var sta = false;

var run = false;

function start() {
    return (!navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i));
}

function setup() {
    if (start()) {
        run = true;
        createCanvas(600, 400);

        bird = new Bird();
    } else {
        document.getElementById("tip").style.display = 'block';
    }
}

function draw() {
    if (run) {
        if (bird.alive && !bird.success) {
            background(0);
            bird.update();
            bird.show();
            if (bird.success) {
                bird.upgrade();
            }
        } else if (!bird.alive) {
            if (!sta) {
                sta = true;
                share.fadeIn(500);
            }
        }
    }
}

function keyPressed() {
    if ((key === 'a')) {
        bird.up();
        bird.btn++;
    }

    if ((key === 's')) {
        bird.down();
        bird.btn++;
    }

    if (key === ' ') {
        bird.renew();
        share.fadeOut(100);
        sta = false;
    }
}

